<template>
  <div class="fillcontain">
    <head-top></head-top>
    <div class="table_container">
      <el-table
        v-loading="loading"
        :data="adminList"
        style="width: 100%">
        <el-table-column
          prop="id"
          label="id"
          width="180">
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="password"
          label="密码"
          width="220">
        </el-table-column>
        <el-table-column
          label="身份"
          width="180">
          <template slot-scope="scope">
            <span>{{getRole(scope.row.garde)}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="状态">
          <template slot-scope="scope">
            <span>{{getStatus(scope.row.state)}}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="Pagination" style="text-align: left;margin-top: 10px;">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="20"
          layout="total, prev, pager, next"
          :total="count">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  import headTop from '@/components/headTop'
  export default {
    name: "adminList",
    components: {
      headTop
    },
    data(){
      return {
        offset: 0,
        limit: 20,
        count: 0,
        currentPage: 1,
      }
    },
    created () {
      this.$store.dispatch('getAdminList')
    },
    computed: {
      ...mapState(['adminList']),
      loading: function () {
        if (this.adminList.length === 0) {
          return true
        } else
          return false
      }
    },
    methods: {
      getRole(roleCode) {
        if (parseInt(roleCode) === 0) {
          return '系统管理员'
        } else
          return '普通管理员'
      },
      getStatus(statusCode) {
        if (parseInt(statusCode) === 0) {
          return '在职'
        } else
          return '离职'
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.offset = (val - 1)*this.limit;
        this.getAdmin()
      },
      getData() {

      }
    }
  }

</script>

<style scoped>

</style>
